<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY nbsp "&#x00A0;">
]>
<xsl:stylesheet
	version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:msxml="urn:schemas-microsoft-com:xslt"
	xmlns:umbraco.library="urn:umbraco.library"
	xmlns:tagsLib="urn:tagsLib"
  xmlns:BlogLibrary="urn:BlogLibrary"
  xmlns:Blog="urn:Blog"
	exclude-result-prefixes="msxml umbraco.library BlogLibrary Blog tagsLib">
  <xsl:output method="html" omit-xml-declaration="yes"/>

  <xsl:param name="currentPage"/>

  <xsl:variable name="currentBlog" select="Blog:XmlCurrent(number($currentPage/@id))" />
  <xsl:variable name="blogCategory" select="$currentBlog/* [@alias='category' or name()='category']"/>

  <xsl:template match="/">
    <ul class="tagCloud">
      <li>
        <a href="{umbraco.library:NiceUrl($currentBlog/@id)}">All</a>
        <span>
          &nbsp;(<xsl:value-of select="count($currentBlog//*[(@isDoc or name()='node') and BlogLibrary:IsType('BlogPost', @id)])"/>)
        </span>
      </li>
      <xsl:choose>
        <xsl:when test="string-length($blogCategory) &gt; 0">
          <xsl:call-template name="listCategories">
            <xsl:with-param name="category" select="$blogCategory"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="listCategories">
            <xsl:with-param name="category" select="'default'"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </ul>
  </xsl:template>

  <xsl:template name="listCategories">
    <xsl:param name="category"/>
    <xsl:for-each select="tagsLib:getAllTagsInGroup($category)/tags/tag">
      <xsl:sort select="." order="ascending"/>
      <xsl:variable name="categoryName" select="./text()"/>
      <xsl:if test="count($currentBlog//*[(@isDoc or name()='node') and BlogLibrary:IsType('BlogPost', @id) and contains(./tags, $categoryName)]) &gt; 0">
        <li>
          <xsl:attribute name="class">
            <xsl:choose>
              <xsl:when test="@nodesTagged &gt; 5">
                <xsl:value-of select="string('tagweight5')"  />
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="concat('tagweight',@nodesTagged)"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:attribute>
          <a href="{umbraco.library:NiceUrl($currentBlog/@id)}?filterby={.}">
            <xsl:value-of select="."/>
          </a> (<xsl:value-of select="@nodesTagged"/>)
        </li>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>